﻿using System.Text.RegularExpressions;

namespace Spotted.WebApi.Extensions
{
    public static class StringExtensions
    {
        /// <summary>
        /// Parse of the name of the controller without affecting the case
        /// </summary>
        /// <param name="str">The string instance being extended</param>
        /// <returns></returns>
        public static string AsControllerName(this string str)
        {
            Regex regex = new Regex(@"^(?<controller>\w+)Controller$", RegexOptions.IgnoreCase);
            var matches = regex.Match(str);
            if (matches.Success)
                return matches.Groups["controller"].Value;

            return null;
        }
    }
}